using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using NUnit.Framework;
using WatiN.Core;
using WatiN.Core.DialogHandlers;

namespace WaxLibTest
{
    [TestFixture]
    public class WatiNTests
    {
        [Test]
        public void SimpleJavaDialogHandler()
        {
            IE.Settings.AutoMoveMousePointerToTopLeft = false;
            IE.Settings.MakeNewIeInstanceVisible = true;

            using(WatiN.Core.IE ie = new IE(Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")))
            {
                ie.BringToFront();
                Assert.AreEqual("Alert test", ie.Link("linkAlert").Text);

                WatiN.Core.DialogHandlers.SimpleJavaDialogHandler handler = new SimpleJavaDialogHandler();
                ie.DialogWatcher.Add(handler);


                ie.Link("linkAlert").Click();
                
                Assert.AreEqual("This is an alert message", handler.Message);
            }
        }

        [Test]
        public void ConfirmJavaDialogHandler()
        {
            IE.Settings.AutoMoveMousePointerToTopLeft = false;
            IE.Settings.MakeNewIeInstanceVisible = true;

            using (WatiN.Core.IE ie = new IE(Path.Combine(System.Environment.CurrentDirectory, "testpage1.htm")))
            {
                ie.BringToFront();
                WatiN.Core.DialogHandlers.ConfirmDialogHandler handler = new ConfirmDialogHandler();
                ie.DialogWatcher.Add(handler);
                
                ie.Link("linkConfirm").ClickNoWait();
                handler.WaitUntilExists(2000);

                Assert.AreEqual("Continue", handler.Message);

                handler.OKButton.Click();
                
                
            }
        }
    }
}
